<?php

$lp_root_path = '../';

define('INSIDE', true);
include( $lp_root_path. 'extension.inc');
include($lp_root_path. 'common.'.$phpEx);
include_once($lp_root_path. 'classes/templates.class.'.$phpEx);
include_once($lp_root_path. 'procedures.class.'.$phpEx);
include_once($lp_root_path. 'classes/json_data_classes.'.$phpEx);

$dentro=check_user();


$user_id = $_SESSION['id_usuario'];

$result = new json_request();

/*
ERROR LIST:

-1		->	No session
-2		->	No request data, missing "jsondata" parameter
-3		->	Type not implemented
-4		->	Operation not implemented
-5		->	Exception

*/

if(!$dentro)
{
	$result->error=1;
	$result->error_number=-1;
	echo "no_session";
}
else
{
	if($jsonraw==null)
	{
		$result->error=1;
		$result->error_number=-2;
		echo "bad_request";
	}
	else
	{
		$jsonraw = str_replace("@","\"",$jsonraw);
		$jsonraw = str_replace('\"','"',$jsonraw);
		$request = json_decode($jsonraw);

		$sp = new procedures();

		try
		{
			$row = $sp->sp_users_getMessage($user_id,$request->data);
		}
		catch (exception $e)
		{
			die($e->getMessage());
		}
	}
}

echo '
		<p>Message from: <span>'.$row[0]["fromUserId"].'</span></p>
		<p>At: <span>'.$row[0]["time"].'</span></p>
		<p>Type: <span>'.$row[0]["type"].'</span></p>
		<p>Content:</p>
		<p>'.$row[0]["logData"].'</p>
';

?>
